// pages/order/order.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		uid: "",
		data: '',
		pg: 1,
		cs: 0,
		http: getApp().globalData.map,
		pd:false,
		xs:0,
		data:[]
	},

	onShow: function() {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data,
					data:[]
				})
				this.tj()
			}
		})
	},
	tj() {
		wx.showToast({title: '加载中', icon: 'loading'});
		wx.request({
			url: getApp().globalData.http + 'action=shopServerList&sta=' + this.data.cs + '&uid=' + this.data.uid.uid + '&pg=' +
				this.data.pg,
			success: (e) => {
				console.log(e)
				let c=this.data.data
				let a=[]
				e.data.data.forEach(function sta(item,index){
					c.push(item)
					if(item.Status==0){
						a.push('待付款')
					}else if(item.Status==1){
						a.push('待使用')
					}else if(item.Status==3){
						a.push('待评价')
					}
				})
				if(e.data.data.length<15){
					this.setData({
						pd:true
					})
				}
				if(e.data.data.length==0){
					this.setData({
						xs:1
					})
				}else{
					console.log(1)
					this.setData({
						xs:0
					})
				}
				this.setData({
					data: c,
					zt:a
				})
				wx.hideToast();
			}
		})
	},
	ovo() {
		if (this.data.pd == 'false') {
			let a = this.data.pg + 1
			this.setData({
				pg: a
			})
			this.tj()
		}
	},
	dele(en){
		wx.showModal({
					title:'您确定要删除订单吗？',
					success:(e)=>{
						console.log(e)
						if(e.confirm){
							wx.request({
								url:getApp().globalData.http+'action=deleteServerOrder&oid='+en.currentTarget.dataset.id+'&uid='+this.data.uid.uid,
								success:(e)=>{
									console.log(e)
									this.cut()
								}
							})
						}
					}
				})
	},
	cut(e){
		console.log(e)
		this.setData({
			cs:e.currentTarget.dataset.id,
			data:[],
			pg:1
		})
		this.tj()
	},
	cancellation(res){
		wx.showModal({
			title:'您确定要取消订单吗？',
			success:(e)=>{
				console.log(e)
				if(e.confirm){
					wx.request({
						url:getApp().globalData.http+'action=canelServerOrder&id='+res.currentTarget.dataset.id+'&userID='+this.data.uid.uid,
						success:(e)=>{
							this.setData({
								data:[]
							})
							this.cut()
						}
					})
				}
			}
		})
	},
	dj(e){
		wx.navigateTo({
			url:'list/list?id='+e.currentTarget.dataset.id
		})
	},
	qrsh(en){
		wx.navigateTo({
			url:'pj/pj?id='+en.currentTarget.dataset.id +'&shopid='+en.currentTarget.dataset.num
		})
	}
})
